<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link href="__LAYUI__/layui/css/layui.css" media="all" rel="stylesheet">
		<link href="__LAYUI__/adminui/dist/css/admin.css" media="all" rel="stylesheet">
	</head>
	<style>
		.layui-icon-ok{color:#c2c2c2!important;}
		.layui-form-checked:hover>div,
		.layui-form-checked>div {
			background-color: #16baaa !important;
		}
		.layui-form-checked:hover>i,
		.layui-form-checked>i {
			color: #16baaa !important;
			border-color: #16baaa !important;
		}
	</style>
	{include file="info" /}
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-tab">
								<div class="layui-tab-content">
									<div class="layui-tab-item layui-show">
										<div class="layui-form layui-form-pane">
											<div class="layui-form-item">
												<label class="layui-form-label">角色<em>*</em></label>
												<div class="layui-input-block">
													<select name="cateId" lay-filter="aihao">
														<option value="" selected>请选择角色</option>
														{notempty name="$cateData"}
														{volist name="cateData" id="vo"}
														<option {notempty name="$info" }{if
															$vo.id==$info.cateId}selected{/if}{/notempty}
															value="{$vo.id}">{$vo.name}</option>
														{/volist}
														{/notempty}
													</select>
												</div>
											</div>
											<div class="layui-form-item">
												<label class="layui-form-label">账号<em>*</em></label>
												<div class="layui-input-block">
													<input type="text" name="username" value="{$info.username?:''}"
														placeholder="请输入账号" class="layui-input">
												</div>
											</div>
											<div class="layui-form-item">
												<label class="layui-form-label">昵称<em>*</em></label>
												<div class="layui-input-block">
													<input type="text" name="nickname" value="{$info.nickname?:''}"
														placeholder="请输入昵称" class="layui-input">
												</div>
											</div>
											<div class="layui-form-item">
												<label class="layui-form-label">密码<em>*</em></label>
												<div class="layui-input-block">
													<input type="password" name="password_old"
														value="{$info.password_old?:''}" placeholder="请输入密码"
														lay-affix="eye" class="layui-input">
												</div>
											</div>
											<div class="layui-form-item layui-form-text">
												<label class="layui-form-label">备注</label>
												<div class="layui-input-block">
													<textarea name="postscript" placeholder="请输入备注"
														class="layui-textarea">{$info.postscript?:''}</textarea>
												</div>
											</div>
											<div class="layui-form-item">
												<label class="layui-form-label">创建时间</label>
												<div class="layui-input-inline">
													{notempty name="$info"}
													<input type="text" class="layui-input" disabled
														value="{:date('Y-m-d H:i:s',$info.create_time)}">
													{else/}
													<input type="text" class="layui-input" disabled
														value="{:date('Y-m-d H:i:s',time())}">
													{/notempty}
												</div>
											</div>
											<div class="layui-form-item">
												<label class="layui-form-label">状态</label>
												<div class="layui-input-inline">
													{notempty name="$info"}
													<input type="checkbox" name="status" value="{$info.status?:1}"
														lay-skin="tag" lay-filter="tagstatus"
														title="{$info.status==1?'启用':'禁用'}" {if
														$info.status==1}checked{/if}>
													{else/}
													<input type="checkbox" name="status" value="1" lay-skin="tag"
														lay-filter="tagstatus" title="启用" checked>
													{/notempty}
												</div>
											</div>
											{notempty name="$info"}
											<input type="hidden" name="id" value="{$info.id}">
											{/notempty}
											<div
												class="layui-form-item {if MyAuto('myadmin','admin','edit')==false}layui-hide{/if}">
												<button class="layui-btn" lay-submit lay-filter="submit"> 保存 </button>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
<script>
	layui.use(["layer", "jquery", "form"], function() {
		var layer = layui.layer;
		var $ = layui.jquery;
		var form = layui.form;
		form.on("checkbox(tagstatus)", function(data) {
			if (data.elem.checked) {
				$("input[name='status']").val(1).attr("title", "启用").attr("checked", true);
				$(".layui-form-checkbox div").text("启用");
			} else {
				$("input[name='status']").val(2).attr("title", "禁用").removeAttr("checked");
				$(".layui-form-checkbox div").text("禁用");
			}
		});
		form.on("submit(submit)", function(data) {
			if (!data.field.status) {
				data.field.status = "2";
			}
			$.ajax({
				url: "{:url('admin/edit')}",
				data: data.field,
				type: "post",
				success: function(res) {
					if (res.code == 0) {
						top.notify.success(res.msg, "topRight");
						setTimeout(function() {
							var index = parent.layer.getFrameIndex(window
							.name); // 先得到当前 iframe 层的索引
							parent.layer.close(index); // 再执行关闭
						}, 1000)
					} else {
						top.notify.error(res.msg, "topRight");
					}
				}
			})
			return false;
		})
	});
</script>